Conversation
- Add database schema for problem_reports_trip and problem_reports_stop - Implement REST API handlers for submitting problem reports - Add manual FTS queries to support route_search and stop_search - Optimize SQL queries to use :exec where appropriate - Cleanup legacy/unused SQL queries
…ffective distance handling
…ieval in trip details
…handling and stop predictions
…ulation and deviation handling
…oved to rt service)
…s since a given service date
…hicleStopSequence function
… functions for trip delay information
…led status based on vehicle data
Replace realtimeService dependency with direct GTFS-RT trip update consumption for schedule deviation and stop position resolution. Use service-date-aware time calculations via CalculateSecondsSinceServiceDate. Remove dead code (block-level position calculation, redundant schedule deviation methods, pass-through setBlockTripSequence). Propagate request
…ffective distance handling
…ulation and deviation handling
Replace realtimeService dependency with direct GTFS-RT trip update consumption for schedule deviation and stop position resolution. Use service-date-aware time calculations via CalculateSecondsSinceServiceDate. Remove dead code (block-level position calculation, redundant schedule deviation methods, pass-through setBlockTripSequence). Propagate request
… block trip sequence calculation
…vehicle parameter
…e situation ID handling
|
Hey @aaronbrethorst I think this branch is ready to be merged now. I suggest we do a squash and merge so our main branch stays linear, since rebasing was too complex to resolve. |
aaronbrethorst
left a comment
There was a problem hiding this comment.
Hey Ahmed, thanks for taking the time to make this substantial improvement to the trip status and vehicle status logic. The overall direction here is excellent: aligning with the Java OBA server's actual semantics for schedule relationships, introducing stale detection, consolidating duplicated code across handlers, and adding thorough test coverage (~1,400 lines of new tests!) are all meaningful wins. The StaleDetector is particularly well-designed, and the bug fixes (timezone time.Local to loc, missing agency prefix on TripID, schedule deviation nanoseconds-to-seconds) are important corrections. Before we can merge this, I will need you to make a couple changes:
Critical
-
VehicleIDno longer includes agency prefix -- behavioral regression. Intrips_helper.go:35, the new code setsstatus.VehicleID = vehicle.ID.ID(e.g.,"v123"), but the old code usedutils.FormCombinedID(agencyID, vehicle.ID.ID)(e.g.,"25_v123"). The OBA API convention uses combined IDs throughout. This is a breaking change for API consumers. Please either restore the combined ID format:if vehicle.ID != nil { status.VehicleID = utils.FormCombinedID(agencyID, vehicle.ID.ID) }
or, if the raw ID is intentional (to match
vehicles_for_agency_handler.go), document it as a deliberate change. -
fillStopsFromSchedulecan overwrite vehicle-derivedClosestStop. Intrips_helper.go:117-119, the guard is:if status.ClosestStop == "" || status.NextStop == "" { api.fillStopsFromSchedule(...) }
But inside
fillStopsFromSchedule, bothClosestStopandNextStopare unconditionally set. If the vehicle-based stop-finding successfully setClosestStopbut notNextStop(e.g., vehicle is at the last stop of a trip), the more accurate vehicle-derived value gets overwritten with a schedule-based guess. Please guard the individual fields:if i > 0 && status.ClosestStop == "" { status.ClosestStop = ... } if status.NextStop == "" { status.NextStop = ... }
-
BuildTripStatususes mismatched trip IDs for stop times vs shape queries.GetStopTimesForTripon line 63 usesactiveTripRawID(which may differ from the requested trip if the vehicle was reassigned within a block), butGetShapePointsByTripIDon line 121 uses the originaltripID. If the vehicle is on a different trip within the block, the shape data and stop times will be for different trips, producing incorrect position/distance calculations. Please use a consistent trip ID for both, and add a comment explaining the choice.
Important
-
Missing
RLockcomment onBuildTripStatus. Themainbranch has// IMPORTANT: Caller must hold manager.RLock() before calling this method.above this function, but the PR dropped it. SinceBuildTripStatuscallsGetSituationIDsForTrip(which documents the same requirement), please restore the comment. -
MockAddVehicleandMockAddVehicleWithOptionsdon't acquirerealTimeMutex. The newMockAddTripUpdateandMockResetRealTimeDataboth correctly lockm.realTimeMutex, but the vehicle mock methods don't. This inconsistency could cause flaky tests. Please add locking to be consistent. -
getFirstStopOfNextTripInBlocksilently swallows three database errors. This new function (trips_helper.go:951-982) returnsnilforGetTrip,GetTripsByBlockIDOrdered, andGetStopTimesForTripfailures with zero logging. Please addslog.Warnlogging consistent with the pattern used incalculateBlockTripSequenceright above it. -
Inconsistent error handling for
BuildTripSchedulefailure. Intrip_details_handler.go:151, aBuildTripSchedulefailure returns a server error response. Intrip_for_vehicle_handler.go:102, the same failure is logged as a warning and the handler continues with nil schedule. These should behave consistently -- either both should degrade gracefully or both should return a server error. -
Missing test coverage for negative schedule deviation (early vehicles). Every test uses positive deviation (late vehicle). The
effectiveScheduleTimecalculation infindStopsByScheduleDeviationflips sign for negative deviations, which could produce unexpected results. Please add at least one test with a negative deviation. -
Missing test for
getFirstStopOfNextTripInBlocksuccess path.TestFindNextStopBySequence_StoppedAtLastStoponly exercises the failure case (trip not in DB). There's no test verifying that the block continuation logic correctly finds the first stop of the next trip in a block. This is a critical real-world scenario. -
findNextStopBySequencehas a redundantserviceDateForBlockparameter. The function signature has bothserviceDate time.TimeandserviceDateForBlock time.Time, but the call site always passes the same value for both. If they're always identical, simplify the signature to avoid confusion.
Fit and Finish
-
Missing doc comments on exported functions.
GetScheduleDeviationandGetStopDelaysFromTripUpdatesintrip_updates_helper.goare exported but have no doc comments. Please add brief comments explaining what they return (seconds, priority of trip-level vs stop-level delay, etc.). -
scheduleRelationshipStatussilently mapsUNSCHEDULED,REPLACEMENT, andDELETEDto"SCHEDULED". While this matches the Java behavior, aDELETEDtrip being reported as"SCHEDULED"is semantically concerning. Please add a comment to thedefaultcase noting the intentional omission. -
Comment in
BuildVehicleStatusclaims avoiding a duplicate query, butgetVehicleDistanceAlongShapeContextualmakes its ownGetShapePointsByTripIDcall. The comment onvehicles_helper.go:128("avoiding a duplicate GetShapePointsByTripID query") is inaccurate. Please either fix the comment or refactor to actually avoid the duplicate query. -
OPTIONAL: Java line number references are fragile. Comments referencing specific line numbers in Java source files (e.g., "line 252-253") will drift as the Java codebase evolves. Consider referencing method names only (e.g.,
TripStatusBeanServiceImpl.getBlockLocationAsStatusBean()). -
shapeRowsToPointsdropsShapeDistTraveledwithout documenting it. The conversion intentionally discards distance data from the database rows. Please note this in the comment so future developers understand distances are recomputed viapreCalculateCumulativeDistances. -
Empty
phasefor canceled trips should be documented.GetVehicleStatusAndPhasereturns""for phase when the trip is canceled. Add a brief comment explaining this matches Java's null-phase behavior for canceled trips.
Thanks again, and I look forward to merging this change.
For this I think for this we should use the activeTripId because it's changing based of the GTFS-RT data. |
…ptions for thread safety
…or BuildTripSchedule failures
…rity on schedule statuses and behavior
…ogging for trip retrieval errors
…lify findNextStopBySequence calls
|
@aaronbrethorst Done |
Fix: #108
Replaces: #408